package exception

import (
	"fmt"
	"net/http"
)

type Apiexcetion struct {
	Bizcode  int
	Httpcode int
	Message  string
}

func (a *Apiexcetion) Error() string {
	return a.Message
}

func NewApiexcetion(code int, format string, a ...any) *Apiexcetion {
	Httpcode := http.StatusInternalServerError
	if code/100 < 6 && code/100 > 0 {
		Httpcode = code
	}
	return &Apiexcetion{
		Bizcode:  code,
		Httpcode: Httpcode,
		Message:  fmt.Sprintf(format, a...),
	}
}
